package com.nineclock.attendance.controller;

import com.nineclock.api.attendance.AttendGroupControllerApi;
import com.nineclock.attendance.dto.AttendGroupDTO;
import com.nineclock.attendance.service.AttendGroupService;
import com.nineclock.common.entity.PageResult;
import com.nineclock.common.entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping
public class AttendGroupController implements AttendGroupControllerApi {
    @Autowired
    private AttendGroupService attendGroupService;

    /**
     * 考勤组: 分页查询
     * @param page
     * @param pageSize
     * @return
     */
    @Override
    @GetMapping("/attendGroup")
    public Result<PageResult<AttendGroupDTO>> queryAttendGroupPage(
        			@RequestParam(value = "page", defaultValue = "1") Integer page,
                    @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageResult<AttendGroupDTO> pageResult = attendGroupService.queryAttendGroupPage(page, pageSize);
        return Result.success(pageResult);
    }

    /**
     *  考勤组: 添加
     * @param attendGroupDTO
     * @return
     */
    @Override
    @PostMapping("/attendGroup")
    public Result addAttendGroup(@RequestBody AttendGroupDTO attendGroupDTO) {
        attendGroupService.addAttendGroup(attendGroupDTO);
        return Result.success();
    }

    /**
     *  获取当前登录用户考勤组
     * @return
     */
    @Override
    @GetMapping("/getAttendGroupByUserId")
    public Result<AttendGroupDTO> getAttendGroupByUserId() {
        AttendGroupDTO attendGroupDTO=attendGroupService.getAttendGroupByUserId();
        return Result.success(attendGroupDTO);
    }
}    